﻿using AFanDa.BLL.BLLService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AFanDa.Admin.filters
{
    public class LoginFilter : ActionFilterAttribute
    {
        LoginService _loginService = null;
        public LoginFilter()
        {
            _loginService = new LoginService();
        }

        public bool IsCheck { get; set; }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!IsCheck)
            {
                return;
            }

            if (filterContext.HttpContext.Request.Cookies["code"] == null)
            {
                filterContext.HttpContext.Response.Redirect("/Login/index");
                return;
            }
            var code = filterContext.HttpContext.Request.Cookies["code"].Value;



            if (code == null)
            {
                filterContext.HttpContext.Response.Redirect("/Login/index");
                return;
            }


            var iq = _loginService.CheckLogin(code);
            if (!iq.Any())
            {
                filterContext.HttpContext.Response.Redirect("/Login/index");
                return;
            }



        }


    }
}